package org.ttitfly.ttcore.service.system;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.PropertyFilter.MatchType;
import org.ttitfly.ttcore.dao.system.DictionaryDao;
import org.ttitfly.ttcore.entity.system.Dictionary;

/**
 * 安全相关实体的管理类, 包括用户,角色,资源与授权类.
 * 
 * @author ttitfly
 */
//Spring Bean的标识.
@Component
//默认将类中的所有函数纳入事务管理.
@Transactional
public class DictionaryManager {

	private static Logger logger = LoggerFactory.getLogger(DictionaryManager.class);

	@Autowired
	private DictionaryDao dictionaryDao;
	
	public Dictionary getDictionary(Long id) {
		return dictionaryDao.get(id);
	}
	
	@Transactional(readOnly = true)
	public List<Dictionary> findBy(String propertyName,Object value, String orderBy, boolean isAsc) {
		return dictionaryDao.findBy( propertyName,  value,  orderBy,  isAsc);
	}
	
	public void saveOrUpdate(Dictionary entity){
		dictionaryDao.save(entity);
	}
	
	public void remove(Long id){
		dictionaryDao.delete(id);
	}
	
	public Dictionary findByProperty(String propertyName,String propertyValue){
		Dictionary dictionary = new Dictionary();
		List<Dictionary> list = dictionaryDao.findBy(propertyName,propertyValue,MatchType.EQ);
		if(list != null && list.size()>0){
			dictionary = list.get(0); 
		}
		return dictionary;
	}
	
	public Dictionary getById(Long id){
		return dictionaryDao.get(id);
	}
	
	public List<Dictionary> getByIds(List<Long> ids){
		if (ids != null && ids.size()>0) {
            return dictionaryDao.getByIds(ids);
        } else {
            return new ArrayList<Dictionary>(0);
        }
	}
	


}
